//
//  UINavigationController+NoShadow.m
//  RemoveNavLine
//
//  Created by 郑东喜 on 2017/3/22.
//  Copyright © 2017年 郑东喜. All rights reserved.
//

#import "UINavigationController+NoShadow.h"

#import <objc/runtime.h>


@implementation UINavigationController (NoShadow)
    
+(void)load {
    Method original = class_getInstanceMethod(self, @selector(viewWillAppear:));
    Method swizzled = class_getInstanceMethod(self, @selector(swizzled_viewWillAppear:));
    method_exchangeImplementations(original, swizzled);
}
    
+ (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    
    return nil;
}
    
- (void)swizzled_viewWillAppear:(BOOL)animated {
    UIImageView *shadow = [UINavigationController findHairlineImageViewUnder:self.navigationBar];
    shadow.hidden = YES;
    
    [self swizzled_viewWillAppear:animated];
}
    
@end
